package com.china08.yxyapi.api.comm.sws;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.config.RabbitConfig;
import com.china08.yxyapi.util.DateUtils;
import com.china08.yxyapi.util.SpringContextUtil;

/*
 * 资源地区
 */
@CrossOrigin
@RestController
public class ResourceSchoolAreaStatisticsDataCrtController {

    @RequestMapping(value = "/api_yw/comm/sws/resource/school/area/crt", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response) throws ParseException {

        long dayCount = DateUtils.difference(DateUtils.formatStrDate4(20171101), DateUtils.formatStrDate4(20180122));
        Long count = new Long(dayCount);

        for (int i = count.intValue(); i > 0; i--) {
            Integer context = DateUtils.formatDate4(DateUtils.subtractDay(DateUtils.formatStrDate4(20180122), i));
            SpringContextUtil.getBean(RabbitTemplate.class).convertAndSend(RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_DAY_NEW_ES, context);
        }

        // SpringContextUtil.getBean(RabbitTemplate.class).convertAndSend(RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_DAY_NEW_ES,
        // 20180124);
    }

}
